package com.bank.Servlets;

import com.bank.dao.impl.QueryDaoImpl;
import com.bank.model.BankCard;
import com.bank.model.Transaction;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/Detail")
public class DetailServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");

        String bankId = request.getParameter("BankId");


        //获取Bankcard的card_id(根据bank_id获取)
        QueryDaoImpl queryDao=new QueryDaoImpl();
        BankCard bankCard = queryDao.queryTb_Bankcard(bankId);
        Integer cardId = bankCard.getCard_id();

        //根据card_id获取明细表
        List<Transaction> transactions = queryDao.queryTb_Transaction(cardId);

        HttpSession session = request.getSession();
        session.setAttribute("Detail_transaction",transactions);

        response.sendRedirect("detail.jsp");
    }
}
